<!DOCTYPE HTML>
<html  lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro">
<head>
    <meta charset="UTF-8">
    <title>内嵌页面</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <script th:src="@{/jQuery/jQuery.js}"></script>
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/js/modules.js}"></script>
</head>
<body>
<div style="width: 60%;margin: 0 auto">
    <form id="register-form" class="layui-form" style="margin-top: 30px">
        <div class="layui-col-md12 layui-form-item">
            <label for="password" class="layui-form-label">旧密码</label>
            <div class="layui-input-inline">
                <input type="text" id="password" name="password" required placeholder="请输入旧密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md12 layui-form-item">
            <label for="newPassword" class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" id="newPassword" name="newPassword" required placeholder="请输入新密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-md12 layui-form-item">
                <div class="layui-input-block" style="margin-top: 20px">
                    <button class="layui-btn" lay-submit lay-filter="toResetPwd">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    layui.form.on('submit(toResetPwd)', function(data){
        console.log('JSON.stringify(data.field)', JSON.stringify(data.field))
        $.ajax({
            url: '/ums/user/update/password',
            method: 'post',
            contentType: 'application/json',
            data: JSON.stringify(data.field),
            success: function (res) {
                if (res && res.code && res.code === '1') {
                    layer.alert(res.msg ? res.msg : '重置密码失败, 请联系管理员')
                    return
                }
                layer.msg('重置成功');
                setTimeout(function () {
                    let index = parent.layer.getFrameIndex(window.name); // 获取当前 iframe 层的索引
                    parent.layer.close(index); // 关闭当前 iframe 弹层
                }, 1000);
            }
        })
        // 阻止表单跳转。如果需要表单跳转，去掉这行。
        return false;
    });
</script>
</body>
</html>